// printRoom Mannamg
function printDataPaymentGroup(type){
	var link = "/messagefolioService";
	var data = { func: "getMessageFolio"}
	simpleserviceWithArgs(link,data,messageGroupSuccess,type);
}

function messageGroupSuccess(data,type){
	///
	var objArray = JSON.parse(data);
	var dateIn = new Date(getCurrentTabData().ResData.date);
	var nextDate = new Date(getCurrentTabData()["ResData"].date);
	var	datecheckOutSet = nextDate.addDate(1).toSystemFormat();
	var dateTo = new Date(datecheckOutSet);
	var formatDateIn = dateIn.getFormatedString();
	var formatDateTo = dateTo.getFormatedString();
	/// Owner
	var nameOwner = getCurrentTabData().Owner.firstName;
	var lastnameOwner = getCurrentTabData().Owner.firstName;
	var phoneOwner = getCurrentTabData().Owner.phone;
	var idOwner = getCurrentTabData().Owner.id;
	var addressLine1Owner = getCurrentTabData().Owner.addressLine1;
	var addressLine2Owner = getCurrentTabData().Owner.addressLine2;
	/// Room
	var rooType = getCurrentTabData().ResData.roomTypeName;
    var	roomName = getCurrentTabData().ResData.roomName;
    var priceRateName = "";
    for(var i = 0;i<SharedData.Package.length;i++){
    	if(SharedData.Package[i].id == getCurrentTabData().ResData.priceRateString){
    		priceRateName = SharedData.Package[i].Name;
    	}
    }
    var adultRoom = "";
    var childRoom = "";
    var commaAdultChild = "";
    var sumPerson = 0;
    var adult = 0;
	var child = 0;
	var rooms = getCurrentTabData().GroupResvList;
	for(var j=0;j<rooms.length;j++){
		adult+=rooms[j].ResData.adult;
		child+=rooms[j].ResData.child;
	}
	
	
    if(adult!=0)
    	adultRoom = adult+" Adults";
    if(child!=0)
    	childRoom = child+" Childs";
    if(adult!=0&&child!=0)
    	commaAdultChild = ","
    sumPerson = adult+child;
	/// Price
	var roomsPrice = toCurrencyString(getCurrentTabData().calBalance.roomsPrice);
	var otherCharge = toCurrencyString(getCurrentTabData().calBalance.otherCharge);
	var sumOtherCharge = toCurrencyString(getCurrentTabData().calBalance.otherTax+getCurrentTabData().calBalance.roomsTax);
	var roomsTax = toCurrencyString(getCurrentTabData().calBalance.roomsTax);
	var roomdiscount = toCurrencyString(getCurrentTabData().calBalance.roomdiscount);
	var roomdiscountAcc = toCurrencyString(getCurrentTabData().calBalance.roomdiscountAcc);
	var payprice = toCurrencyString(getCurrentTabData().calBalance.payprice);
	var roomsTaxAcc = toCurrencyString(getCurrentTabData().calBalance.roomsTaxAcc);
	var TotalWithTax = 	toCurrencyString(getCurrentTabData().calBalance.TotalBalance+getCurrentTabData().calBalance.roomsTax+getCurrentTabData().calBalance.otherTax);
	var Balance = toCurrencyString((getCurrentTabData().calBalance.TotalBalance+getCurrentTabData().calBalance.roomsTax+getCurrentTabData().calBalance.otherTax)-getCurrentTabData().calBalance.payprice);
	///
    /// payment
    var paymentPrint = "";
    var printPayment = getCurrentTabData().GroupPaymentList;
    if(printPayment!=null){
    	for(var i = 0;i<printPayment.length;i++){
        	paymentPrint += '<tr style="background-color:#F7F9A2">'+
        					"<td>"+new Date(printPayment[i].payDate).getFormatedString()+"</td>" +
    				 		'<td><span>'+printPayment[i].description+'</span></td>'+
    				 		'<td><span style="color:#3b69b3;">&nbsp;</span></td>'+
    				 		'<td><span>&nbsp;</span></td>'+
    				 		'<td><span style="float:right;">&nbsp;</span></td>'+
    				 		'<td><span style="float:right;">0.00</span></td>'+
    				 		'<td><span>&nbsp;</span></td>'+
    				 		'<td><span style="float:right;">'+parseFloat(printPayment[i].amount).toFixed(currencyDecimalPlaces)+'</span></td>'+
    				 		'</tr>';
        }
    }
    /// chargeGroup
    var chargePrintGroup = "";
    var refundPrintGroup = "";
    var disPlayFolioStatusGroup = "";
    var folioNumberGroup = "";
	var dataStateMentListGroup = "";
    var chargeListGroup = getCurrentTabData().ChargeList;
    if(chargeListGroup!=null){
    	 for(var i = 0;i<chargeListGroup.length;i++){
    	    	if(!chargeListGroup[i].isTemp){
    	    		var folioNumber="";
    	    		var q ="";
    	    		var rc="";
    		    	if(chargeListGroup[i].Qty != parseInt(0))
    				{
    					q=Qty+" "+chargeListGroup[i].Qty+" ";
    					rc=roomCharge+"/";
    				}
    		    	if(chargeListGroup[i].FolioId !=0)
    				{
    					disPlayFolioStatusGroup="PI";
    					folioNumberGroup = chargeListGroup[i].FolioId;
    				}
    		    	if(chargeListGroup[i].isRefund){
    		    		refundPrintGroup +=  '<tr style="background-color:#fbc9c8;">'+
	    							 		'<td>'+
	    							 		'<span>'+new Date(chargeListGroup[i].chargeDate).getFormatedString()+'</span>'+
	    							 		'</td>'+
	    							 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeListGroup[i].description+'</span></td>'+
	    							 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatusGroup+" "+folioNumberGroup+'</span></td>'+
	    							 		'<td><span>&nbsp;</span></td>'+
	    							 		'<td><span id=charge'+i+' charge="'+chargeListGroup[i].chargeAmount+'">'+toCurrencyString(chargeListGroup[i].chargeAmount,false)+'</span></td>'+
	    							 		'<td><span id=tax'+i+' tax="'+chargeListGroup[i].tax+'" >'+toCurrencyString(chargeListGroup[i].tax,false)+'</span></td>'+
	    							 		'<td><span>&nbsp;</span></td>'+
	    							 		'<td><span>&nbsp;</span></td>'+
	    							 		'</tr>';
    		    	}
    	    		chargePrintGroup +=  '<tr class="border-top" id="'+chargeListGroup[i].id+'">'+
    						 		'<td>'+
    						 		'<span>'+new Date(chargeListGroup[i].chargeDate).getFormatedString()+'</span>'+
    						 		'</td>'+
    						 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeListGroup[i].description+'</span></td>'+
    						 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatusGroup+" "+folioNumberGroup+'</span></td>'+
    						 		'<td><span>&nbsp;</span></td>'+
    						 		'<td><span id=charge'+i+' charge="'+chargeListGroup[i].chargeAmount+'">'+toCurrencyString(chargeListGroup[i].chargeAmount,false)+'</span></td>'+
    						 		'<td><span id=tax'+i+' tax="'+chargeListGroup[i].tax+'" >'+toCurrencyString(chargeListGroup[i].tax,false)+'</span></td>'+
    						 		'<td><span>&nbsp;</span></td>'+
    						 		'<td><span>&nbsp;</span></td>'+
    						 		'</tr>'+refundPrintGroup;
    	    		refundPrintGroup = "";
    	    	}
    	    }
    }
    /// sum
    var textSumStatement =  '<tr style="background-color:#DDD">'+
						    '<td colspan="4">'+
						    '<span id="payment-account-date" style="padding-left:200px">รวม'+
						    '</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-cost" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.chargePriceAcc,false)+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-tax" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.roomsTaxAcc,false)+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-currency" style="float:right;">'+SharedData.General.defaultCurrency.symbol+'</span>'+
						    '</td>'+
						    '<td>'+
						    '<span id="singlepayment-account-payment" style="float:right;">'+toCurrencyString(getCurrentTabData().calBalance.payprice,false)+'</span>'+
						    '</td>'+
						    '</tr>';
    ///
	var reservation = "";
	if(getCurrentTabData().type=="Group")
		reservation = "G"+getCurrentTabData().resId;
	else
		reservation = getCurrentTabData().resId;
	myWindow=window.open('','','width=783,height=722');
	var headHtml = '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' +
				    '<title></title>' +
				    '<script src="js/jquery-1.8.3.min.js"></script>'+
				    '<link href="css/print/print.css" rel="stylesheet" type="text/css">' +
				    '</head><body>';
	var hotel = '<table align="center" border="0" cellpadding="10" cellspacing="0" width="100%">' +
			    '<tbody>' +
			    '<tr>' +
			    '<td width="65%">' +
			    '<img src="https://s3.amazonaws.com/livestaygriddata/product-images/hotels/logo/logo08042013072057140130407.jpeg" width="152.36276849642" height="160">' +
			    '</td>' +
			    '<td width="35%">' +
			    '<table width="100%">' +
			    '<tbody>' +
			    '<tr>' +
			    '<td>' +
			    '<table style="font-size:11px" width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td colspan="2" style="font-size:14px"><strong>iHotel</strong></td></tr><tr><td colspan="2" width="100%" valign="top">......................................<br>Thakor - 48000<br>Nakhon Phanom, Thailand</td></tr><tr><td width="10%"><strong>Phone:</strong></td><td width="90%">+6642543355</td></tr><tr><td><strong>Fax:</strong></td><td>+6642543377</td></tr><tr><td><strong>Email:</strong></td><td>ihotelthailands@gmail.com</td></tr><tr><td><strong>Website:&nbsp;</strong></td><td>www.ihotel.co.th</td></tr></tbody></table>' +
			    '</td>' +
			    '</tr>' +
			    '</tbody>' +
			    '</table>' +
			    '</td>' +
			    '</tr>' +
			    '</tbody>' +
			    '</table>';
	var message = '<table style="font-size:11px"  ><tr><td colspan="4" >'+objArray.message+'</td></tr></table>';
	var messageThank = '<table style="font-size:11px"  ><tr><td colspan="4" >'+objArray.thxmessage+'</td></tr></table>';
	var Comfort =   '<table class="comfortTable" border="0" align="center" width="100%">' +
					'<tr>' +
					'<td width = "15%" align="right"><span style="font-weight:bold;">Res ID:</span> '+reservation+'</td><td colspan="2" width="30%"></td>'+
					'<td width="20%" align="right"><span style="font-weight:bold;">Check-in:</span>'+formatDateIn+'</td>'+
					'<td width="20%" align="right"><span style="font-weight:bold;">Check-out:</span>'+formatDateTo+'</td>'+
					'<td width="11%"><span class="link">How to use?</span></td>'+
					'</tr></table>';
	var detailResInGroup = "";
	var GroupResvList = getCurrentTabData().GroupResvList;
	var roomType = new Array();
	var roomName = new Array();
	for(var i =0; i<GroupResvList.length;i++){
		roomType.push(GroupResvList[i].ResData.roomTypeName+","+GroupResvList[i].ResData.roomName);
	}
	var tmp = {};
	var tmp2 = {}, out2 = [];
	var arrayRoom = {};
	for(var i =0; i<roomType.length;i++){
		var roomTypeCheck = roomType[i].split(",");
		if(!tmp[roomTypeCheck[0]]) { 
			if(roomTypeCheck[0]==0){
				tmp[roomTypeCheck[0]] = false;
				tmp2[roomTypeCheck[1]] = false;
			}else{
				tmp[roomTypeCheck[0]] = true;
				tmp2[roomTypeCheck[1]] = true;
			}
			arrayRoom[roomTypeCheck[0]] = new Array();
			arrayRoom[roomTypeCheck[0]].push(roomTypeCheck[1]);
		}else{
			arrayRoom[roomTypeCheck[0]].push(roomTypeCheck[1]);
		}
	}
	var detailSetRoom = [];
	for (var key in arrayRoom) {
		   var obj = arrayRoom[key];
		   var roomSet = "";
		   for (var prop in obj) {
			   roomSet += obj[prop]+",";
		   }
		   roomSet = roomSet.substring(0,roomSet.length-1);
		   detailSetRoom.push(key+"("+roomSet+")");
	}
	var textRoomSet ="";
	for(var i = 0;i<detailSetRoom.length;i++){
		textRoomSet += detailSetRoom[i]+"<br>";
	}
	////////////
	var detail = '<table class="borderstatement" style="font-size:11px; margin:10 10 10 10;" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF" width="50%">' +
					'<tr>' +
					'<td colspan = "4"><span style="font-weight:bold;"><center>BOOKING DETAILS</center></span></td>'+
					'</tr>'+
					'<tr><td width="30%" colspan = "1"><span style="font-weight:bold;"><center>Guest Name:</center></span></td><td width="70%" align="left" colspan = "3"><span style="color:#0BA5F6;">'+nameOwner+' '+lastnameOwner+'(<span style="color:red;">P'+idOwner+'</span>)</span></td></tr>'+
					'<tr><td width="15%"><span style="font-weight:bold;"><center>Address:</center></span></td><td width="45%" align="left">'+addressLine1Owner+addressLine2Owner+'</td><td width="15%"><span style="font-weight:bold;"><center>Phone:</center></span></td><td width="25%" align="left">'+phoneOwner+'</td></tr>'+
					'<tr><td colspan = "4">'+
					'<table style="font-size:11px" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF"  width="100%">'+
						'<tr><td width="25" valign="bottom" style="padding:0;"><span style="font-weight:bold;"><center>Created On</center></span></td>'+
						'<td width="25%" valign="bottom" style="padding:0;"><span style="font-weight:bold;"><center>Stay Details</center></span></td>'+
						'<td width="25%" valign="bottom" style="padding:0;"><span style="font-weight:bold;"><center>Room(s)/Person(s)</center></span></td>'+
						'<td width="25%" valign="bottom" style="padding:0;"><span style="font-weight:bold;"><center>Amount </center></span></td></tr>'+
						'<tr><td width="25" valign="top" style="padding-top:0;"><span><center>-</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>'+textRoomSet+formatDateIn+'-'+formatDateTo+'<br>'+priceRateName+'</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>Room(s)/'+sumPerson+'('+adultRoom+commaAdultChild+childRoom+')</center></span></td>'+
						'<td width="25%" valign="top" style="padding-top:0;"><span><center>'+Balance+'</center></span></td></tr>'+
					'</table>'+
					'</td></tr>'+
					''+
					'</table>';
	/// detail Room Statement
	var chargePrint = "";
    var refundPrint = "";
    var disPlayFolioStatus = "";
    var folioNumber = "";
	var dataStateMentList = "";
	for(var i =0;i<getCurrentTabData().GroupResvList.length;i++){
		for(var j =0;j<getCurrentTabData().GroupResvList[i].ChargeList.length;j++){
			var chargeList = getCurrentTabData().GroupResvList[i].ChargeList[j];
	    	if(!chargeList.isTemp){
	    		var folioNumber="";
	    		var q ="";
	    		var rc="";
		    	if(chargeList.Qty != parseInt(0))
				{
					q=Qty+" "+chargeList.Qty+" ";
					rc=roomCharge+"/";
				}
		    	if(chargeList.FolioId !=0)
				{
					disPlayFolioStatus="PI";
					folioNumber = chargeList.FolioId;
				}
		    	if(chargeList.isRefund){
		    		refundPrint +=  '<tr style="background-color:#fbc9c8;">'+
							 		'<td>'+
							 		'<span>'+new Date(chargeList.chargeDate).getFormatedString()+'</span>'+
							 		'</td>'+
							 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeList.description+'</span></td>'+
							 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatus+" "+folioNumber+'</span></td>'+
							 		'<td><span>&nbsp;</span></td>'+
							 		'<td><span id=charge'+i+' charge="'+chargeList.chargeAmount+'">'+toCurrencyString(chargeList.chargeAmount,false)+'</span></td>'+
							 		'<td><span id=tax'+i+' tax="'+chargeList.tax+'" >'+toCurrencyString(chargeList.tax,false)+'</span></td>'+
							 		'<td><span>&nbsp;</span></td>'+
							 		'<td><span>&nbsp;</span></td>'+
							 		'</tr>';
		    	}
	    		chargePrint +=  '<tr class="border-top" id="'+chargeList.id+'">'+
						 		'<td>'+
						 		'<span>'+new Date(chargeList.chargeDate).getFormatedString()+'</span>'+
						 		'</td>'+
						 		'<td><span>'+q+'</span><span name="roomcharge_refund">'+rc+'</span><span id=description'+i+'>'+chargeList.description+'</span></td>'+
						 		'<td><span style="color:#3b69b3;" name="folio_number_onshow">'+disPlayFolioStatus+" "+folioNumber+'</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'<td><span id=charge'+i+' charge="'+chargeList.chargeAmount+'">'+toCurrencyString(chargeList.chargeAmount,false)+'</span></td>'+
						 		'<td><span id=tax'+i+' tax="'+chargeList.tax+'" >'+toCurrencyString(chargeList.tax,false)+'</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'<td><span>&nbsp;</span></td>'+
						 		'</tr>'+refundPrint;
	    		refundPrint = "";
	    	}
		}
		var dateDetailRoom = new Date(getCurrentTabData().GroupResvList[i].ResData.date).getFormatedString();
	    var description = getCurrentTabData().GroupResvList[i].ResData.roomTypeName+" "+ 
	    getCurrentTabData().GroupResvList[i].ResData.roomName+"/"+
		new Date(getCurrentTabData().GroupResvList[i].ResData.date).getFormatedDateAndMonthString()+ " - "+
		new Date(getCurrentTabData().GroupResvList[i].ResData.date).addDate(getCurrentTabData().GroupResvList[i].ResData.span).getFormatedDateAndMonthString()+"/"+
		getCurrentTabData().GroupResvList[i].ResData.id;
	    dataStateMentList += '<tr style="background-color:#CCCCCC;">' +
		'<td>'+dateDetailRoom+'</td>'+
		'<td>'+description+'</td>'+
		'<td colspan="6"></td>'+
		'</tr>'+chargePrint;
	    chargePrint = "";
	}
	///
	var stateMent = '<table  style="font-size:11px;" border="0" width="100%">'+
					'<tr>' +
					'<td colspan = "8"><span style="font-weight:bold;"><center>ACCOUNT STATEMENT</center></span></td>'+
					'</tr>'+
					'</table>'+
					'<table class="borderstatement" style="font-size:11px;"  border="0" bgcolor="#FFFFFF" width="100%">' +
					'<tr style="color:#ABABB4;"><td>Date</td><td>Description-References</td><td>Folio #</td><td>Disc/Allw</td><td>Charges</td><td>Tax</td><td align="right">Currency</td><td align="right">Payment</td></tr>'+
						paymentPrint+
						chargePrintGroup+
						//chargePrint+
						dataStateMentList+
						textSumStatement+
					'</table>';
	var sumAmount = '<table  align="center" bgcolor="#FFFFFF" border="0" cellpadding="10" cellspacing="0" width="100%">' +
				    '<tbody>' +
				    '<tr>' +
				    '<td width="65%">' +
				    '</td>' +
				    '<td width="35%">' +
				    '<table width="100%">' +
				    '<tbody>' +
				    '<tr>' +
				    '<td>' +
				    	'<table style="font-size:11px;" width="100%" border="0" cellpadding="0" cellspacing="0"><tbody>'+
						    '<tr><td width="40%"><strong>Booking Total </strong></td><td width="60%" align="right">'+roomsPrice+'</td></tr>'+
						    '<tr><td width="40%"><strong>Other Charges </strong></td><td width="60%" align="right">'+otherCharge+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Tax </strong></td><td width="60%" align="right">'+sumOtherCharge+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Disc/Allw </strong></td><td width="60%" align="right">'+roomdiscount+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total With Tax </strong></td><td width="60%" align="right">'+TotalWithTax+'</td></tr>'+
						    '<tr><td width="40%"><strong>Total Paid </strong></td><td width="60%" align="right">'+payprice+'</td></tr>'+
						    '<tr><td width="40%"><strong>Balance </strong></td><td width="60%" align="right">'+Balance+'</td></tr>'+
					    '</table>' +
					'</td>' +
				    '</tr>' +
				    '</tbody>' +
				    '</table>' +
				    '</td>' +
				    '</tr>' +
				    '</tbody>' +
				    '</table>';
	myWindow.document.write(headHtml+hotel+message+Comfort+detail+stateMent+sumAmount+messageThank+'<body>');
	myWindow.print();
	myWindow.focus();
}
//